
//根据二叉树创建字符串
//这个题就是画图分析

class Solution4 {
    public String tree2str(TreeNode root) {
        if(root==null){
            return null;
        }
        StringBuilder stringBuilder=new StringBuilder();
       tree2strChild(root,stringBuilder);
       return stringBuilder.toString();
    }
    public void tree2strChild(TreeNode  t,StringBuilder stringBuilder){
                if(t==null){
                    return;
                } 
                stringBuilder.append(t.val);
                if(t.left!=null){
                   
                    stringBuilder.append("(");
                    tree2strChild(t.left,stringBuilder);
                    stringBuilder.append(")");
                }else{//左边为空的前提下
                    if(t.right!=null){
                        stringBuilder.append("()");
                    }else{
                        return;
                    }
                }
                if(t.right==null){
                    return;
                }
                else{
                    stringBuilder.append("(");
                    tree2strChild(t.right,stringBuilder);
                     stringBuilder.append(")");
                }
    }
}